<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>13</title>
		<script src="lib/vue.js"></script>
	</head>
	<body>
		<div id="example">
			<input placeholder="Add to todo" v-model="newTodoText" v-on:keyup.enter="addNewTodo" />
			<ul>
				<li is="todo-item" v-for="(todo,index) in todos" v-bind:title="todo" v-on:remove="todos.splice(index,1)"></li>
			</ul>
		</div>
		
	</body>
	<script type="text/javascript">
		Vue.component('todo-item',{
			template:'\
			<li>\
			{{title}}\
			<button v-on:click="$emit(\'remove\')">X</button>\
			</li>\
			',
			props:['title']
		})
		
		new Vue({
			el:"#example",
			data:function(){
				return {
					newTodoText:'',
					todos:[
					     'one',
					     'two',
					     'three'
					]
				}
			},
			methods:{
				addNewTodo:function(){
					this.todos.push(this.newTodoText)
					this.newTodoText=''
				}
			}
		})
	</script>
</html>
